package com.buydeem.share.customjson.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * @author zengchao
 * @version 1.0.0
 * @ClassName BigDecimalSerialize.java
 * @Description TODO
 * @createTime 2021年06月23日 20:47:00
 */
public class PercentSerialize extends JsonSerializer<BigDecimal> {
    private final DecimalFormat df = new DecimalFormat("##.00%");
    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value == null){
            gen.writeNull();
        }else {
            gen.writeString(df.format(value));
        }
    }
}
